clear;
cover_1=imread('C:/Code/Matlab/HW1_data/cover_2.jpg');
cover_1=cover_1(:,:,1);
Qulatity=0.005;
C=detectHarrisFeatures(cover_1,'MinQuality',Qulatity);
ratio_array=[];
for angle=0:15:360
    rotate_i=imrotate(cover_1,angle);
    C_rotate=detectHarrisFeatures(rotate_i,'MinQuality',Qulatity);
    ratio=MatchPoint(C,C_rotate,size(cover_1),angle);
    ratio_array=[ratio_array,ratio];
    fprintf('%d : %8.5f\n',angle,ratio);
end
figure;
createfigure(0:15:360,ratio_array,'Harris keypoint detector robustness against rotation');
ratio_array2=[];
scale_array=[];
for size_ratio=0:1:8
    scale_size=1.2^size_ratio;
    scale_array=[scale_array,scale_size];
    resize_img=imresize(cover_1,scale_size,'bicubic');
    C_resize=detectHarrisFeatures(resize_img,'MinQuality',Qulatity);
    ratio=MatchPoint2(C,C_resize,scale_size);
    ratio_array2=[ratio_array2,ratio];
end
figure;
createfigure2(scale_array,ratio_array2,'Harris keypoint detector robustness against scale');
% function match=MatchPoint(C1,C2,centerLocation,angle)
%     origin_locations=C1.Location;
%     match_locations=C2.Location;
%     move_locations(:,1)=origin_locations(:,1)-centerLocation(1);
%     move_locations(:,2)=origin_locations(:,2)-centerLocation(2);
%     move_locations=move_locations*[cos(angle),-sin(angle);sin(angle),cos(angle)];
%     move_locations(:,1)=origin_locations(:,1)+centerLocation(1);
%     move_locations(:,2)=origin_locations(:,2)+centerLocation(2);
%     size_locations=size(move_locations);
%     size_locations2=size(match_locations);
%     nums=0;
%     for i=1:size_locations(1)
%         check=false;
%         for j=1:size_locations2(1)
%             if abs(match_locations(j,1)-move_locations(i,1))<=2&&abs(match_locations(j,2)-move_locations(i,2))
%                 check=true;
%                 break
%             end
%         end
%         nums=nums+check;
%     end
%     match=nums/size_locations(1);
% end
% imshow(cover_1);
% hold on;
% plot(C);